
public class DLL<T> {
	
	 private int size;      	/** list size, counting head and tail */
	 private DLLNode<T> head; 		/** the head node of the list         */
	 private DLLNode<T> tail; 		/** the tail node of the list         */
	

	 //default constructor, list always has 2 nodes (head, tail)
	public DLL(){
		size=2;
		head=new DLLNode();
		tail=new DLLNode();
		head.setNext(tail);
		tail.setPrev(head);
		
		
	}
	
	
	//accessors and mutators
	public DLLNode<T> getHead(){
		return head;
	}
	public void setHead(DLLNode<T> newHead){
		head=newHead;
	}
	public int getSize(){
		return size;
	}
	public void setSize(int what){
		size=what;
	}
	public DLLNode<T> getTail(){
		return tail;
	}
	public void setTail(DLLNode<T> newTail){
		tail=newTail;
	}
	
	
	//General Methods
	
	
	//adds new node at head of list, takes a record as paramater
	public boolean add(Record dllData){
		DLLNode<T> newNode=new DLLNode(dllData,null);
		
		newNode.setNext(head.getNext());
		newNode.setPrev(head);
		
		head.setNext(newNode);
		
		newNode.getNext().setPrev(newNode);
		
		this.setSize(size+1);	//increments size
		return true;
	}
	
	
	//searches list for a record given as a paramter, returns true if found
	public boolean contains(Record dllData){
		
		int dllSize=this.getSize();
		DLLNode<T> temp=head;
		
		for(int i=0; i<dllSize; i++){
			if(temp.getNodeData()!=null){
			if(temp.getNodeData().equals(dllData)){
					
				return true;
			}
			
			
			}
			
				//goes to next node in list, provided it isn't the tail
			if(temp.getNext()!=null){
			temp=temp.getNext();
			
			

			
			}
		}
		
		
		
		
		return false;
	}
	
	//finds a record in the list and removes it
	public boolean remove(Record dllData){
		
		
		DLLNode<T> temp=head.getNext();
		
		while(temp!=tail){
			
		
			
			if(temp.getNodeData()!=null){
			
				//if match is found node is unlinked from list
			if(temp.getNodeData().equals(dllData)){
				DLLNode<T> next=temp.getNext();
				DLLNode<T> prev=temp.getPrev();
				
				next.setPrev(prev);
				
				
				prev.setNext(next);
				
				
				
				temp.setNext(null);
				temp.setPrev(null);
				temp.setNodeData(null);
				
				
				this.setSize(size-1);		//decrements size
				return true;
			}
			}
			//goes to next node in list
			if(temp.getNext()!=null){
				
				temp=temp.getNext();	
			}
			
			}
			
		return false;
	}
	
	//converts list into one String, called in Phonebook class
	public String toString(){
		
		
		String a="";		//String to be returned
		int counter=0;		//counter to pass on to DLLNode toString method
		int theSize=this.getSize();
		DLLNode<T> temp=this.getHead();		//starting point
		
		
		a+="There are "+theSize+" entries";
		a+="\nGoing forward";
		
		while(temp!=null){
		
			
			a+=temp.toString(counter);		//calls DLLNode toString method
			temp=temp.getNext();
			counter++;
		}
		
		a+="\n\nGoing backwards";
		temp=this.getTail();				//starts at tail and goes backwards
		counter=size-1;
		
		while(temp!=null){
			
			a+=temp.toString(counter);
			temp=temp.getPrev();
			
			counter--;
		}
		a+="\n";
		
		
		
		return a;
	}
	
	
}